<!-- Christmas Effect Component -->
<template>
  <div class="christmas-effects">
    <transition name="message">
      <div class="christmas-message" v-if="showMessage">
        <div class="message-content">
          <div class="message-snowflakes">
            <div v-for="n in 20" :key="n" class="message-snowflake">❄</div>
          </div>
          <div class="message-stars">
            <div v-for="n in 10" :key="n" class="message-star">⭐</div>
          </div>
          <div class="message-text-container">
            <div class="message-text message-text-merry">Merry</div>
            <div class="message-text message-text-christmas">Christmas</div>
          </div>
          <div class="message-decorations">
            <span class="message-decoration">🎄</span>
            <span class="message-decoration">🎅</span>
            <span class="message-decoration">🎁</span>
            <span class="message-decoration">🔔</span>
          </div>
        </div>
      </div>
    </transition>

    <!-- Christmas Tree -->
    <div class="christmas-tree-container">
      <div class="christmas-tree" 
           @click="triggerEasterEgg" 
           :class="{ 'easter-egg-active': isEasterEggActive }">
        <div class="star">★</div>
        <div class="lights">
          <div v-for="n in 20" :key="n" class="light" :class="'light-' + (n % 4)"></div>
        </div>
        <img src="@/assets/images/tree.png" alt="Christmas Tree" class="tree-image">
        <div class="gifts-shower" v-if="isEasterEggActive">
          <div v-for="n in 15" :key="n" class="gift-particle">🎁</div>
        </div>
      </div>
      <div class="click-hint">
        <div class="click-icon">🖱</div>
        <div class="click-text">Click me!</div>
      </div>
      <div class="music-control" @click.stop="toggleMusic" v-if="isMusicPlaying">
        <div class="music-icon">{{ isMusicPlaying ? '🔊' : '🔇' }}</div>
      </div>
    </div>
    
    <!-- Santa -->
    <div class="santa">🎅</div>

    <!-- Gift Boxes -->
    <div class="gifts">
      <div class="gift gift-1">🎁</div>
      <div class="gift gift-2">🎁</div>
      <div class="gift gift-3">🎁</div>
    </div>

    <!-- Bells -->
    <div class="bells">
      <div class="bell bell-1">🔔</div>
      <div class="bell bell-2">🔔</div>
    </div>
    
    <!-- Snow Effect -->
    <div class="snow-container">
      <div v-for="n in 400" :key="n" class="snow"></div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'ChristmasEffect',
  data() {
    return {
      showMessage: false,
      isEasterEggActive: false,
      easterEggTimeout: null,
      messageTimeout: null,
      bellAudio: null,
      bgMusic: null,
      isMusicPlaying: false
    }
  },
  methods: {
    initAudio() {
      
      // 背景音乐 - Jingle Bells
      if (!this.bgMusic) {
        this.bgMusic = new Audio('https://cdn.pixabay.com/audio/2024/11/24/audio_f0957fe119.mp3');
        this.bgMusic.loop = true;
        this.bgMusic.volume = 0.3; // 降低音量到30%
        this.bgMusic.load();
      }
    },
    playMusic() {
      if (!this.isMusicPlaying && this.bgMusic) {
        this.bgMusic.play().catch(error => {
          console.log('Background music play failed:', error);
        });
        this.isMusicPlaying = true;
      }
    },
    triggerEasterEgg() {
      console.log('triggerEasterEgg called');
      
      if (this.isEasterEggActive) {
        console.log('Easter egg already active');
        return;
      }
      
      // 初始化音频
      this.initAudio();
      
      // 显示 Merry Christmas 消息
      console.log('Showing message');
      this.showMessage = true;
      clearTimeout(this.messageTimeout);
      this.messageTimeout = setTimeout(() => {
        this.showMessage = false;
      }, 4000);
      
      // 触发彩蛋动画
      console.log('Activating easter egg');
      this.isEasterEggActive = true;
      
      // 播放铃铛音效
      console.log('Playing bell sound');
      if (this.bellAudio) {
        this.bellAudio.currentTime = 0;
        this.bellAudio.play().catch(error => {
          console.log('Bell sound play failed:', error);
        });
      }
      
      // 播放背景音乐
      this.playMusic();
      
      // 重置彩蛋状态
      clearTimeout(this.easterEggTimeout);
      this.easterEggTimeout = setTimeout(() => {
        console.log('Deactivating easter egg');
        this.isEasterEggActive = false;
      }, 3000);
    },
    toggleMusic() {
      if (this.bgMusic) {
        if (this.isMusicPlaying) {
          this.bgMusic.pause();
        } else {
          this.bgMusic.play().catch(error => {
            console.log('Background music play failed:', error);
          });
        }
        this.isMusicPlaying = !this.isMusicPlaying;
      }
    }
  },
  beforeDestroy() {
    clearTimeout(this.easterEggTimeout);
    clearTimeout(this.messageTimeout);
    
    // 停止并清理音频
    if (this.bellAudio) {
      this.bellAudio.pause();
      this.bellAudio = null;
    }
    if (this.bgMusic) {
      this.bgMusic.pause();
      this.bgMusic = null;
    }
  }
}
</script>

<style scoped>
.christmas-effects {
  position: fixed;
  width: 100%;
  height: 100%;
  z-index: 1000;
}

/* Christmas Tree Styles */
.christmas-tree-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 150px;
  height: 200px;
  z-index: 1001;
}

.christmas-tree {
  width: 100%;
  height: 100%;
  animation: treeFloat 3s ease-in-out infinite;
  transform-origin: bottom center;
  cursor: pointer;
  transition: transform 0.3s ease;
  pointer-events: auto;
}

.tree-image {
  width: 150px;
  height: auto;
  filter: drop-shadow(0 0 10px rgba(0,0,0,0.3));
  animation: treePulse 2s ease-in-out infinite;
  position: relative;
  z-index: 2;
}

.easter-egg-active .tree-image {
  animation: treeShake 0.5s ease-in-out;
}

/* Christmas Lights */
.lights {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 2;
}

.light {
  position: absolute;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  animation: lightBlink 1s infinite;
}

.light-0 { background: #ff0000; } /* Red */
.light-1 { background: #00ff00; } /* Green */
.light-2 { background: #ffff00; } /* Yellow */
.light-3 { background: #0000ff; } /* Blue */

/* Position lights around the tree */
.light:nth-child(1) { left: 70%; top: 10%; animation-delay: 0.1s; }
.light:nth-child(2) { left: 30%; top: 15%; animation-delay: 0.2s; }
.light:nth-child(3) { left: 75%; top: 20%; animation-delay: 0.3s; }
.light:nth-child(4) { left: 25%; top: 25%; animation-delay: 0.4s; }
.light:nth-child(5) { left: 80%; top: 30%; animation-delay: 0.5s; }
.light:nth-child(6) { left: 20%; top: 35%; animation-delay: 0.6s; }
.light:nth-child(7) { left: 85%; top: 40%; animation-delay: 0.7s; }
.light:nth-child(8) { left: 15%; top: 45%; animation-delay: 0.8s; }
.light:nth-child(9) { left: 90%; top: 50%; animation-delay: 0.9s; }
.light:nth-child(10) { left: 10%; top: 55%; animation-delay: 1s; }
.light:nth-child(11) { left: 85%; top: 60%; animation-delay: 1.1s; }
.light:nth-child(12) { left: 15%; top: 65%; animation-delay: 1.2s; }
.light:nth-child(13) { left: 80%; top: 70%; animation-delay: 1.3s; }
.light:nth-child(14) { left: 20%; top: 75%; animation-delay: 1.4s; }
.light:nth-child(15) { left: 75%; top: 80%; animation-delay: 1.5s; }
.light:nth-child(16) { left: 25%; top: 85%; animation-delay: 1.6s; }
.light:nth-child(17) { left: 70%; top: 90%; animation-delay: 1.7s; }
.light:nth-child(18) { left: 30%; top: 95%; animation-delay: 1.8s; }
.light:nth-child(19) { left: 65%; top: 97%; animation-delay: 1.9s; }
.light:nth-child(20) { left: 35%; top: 99%; animation-delay: 2s; }

/* Santa Animation */
.santa {
  position: fixed;
  top: 100px;
  left: -100px;
  font-size: 48px;
  animation: santaFly 20s linear infinite;
  z-index: 1002;
  pointer-events: none;
}

/* Gift Boxes */
.gifts {
  position: fixed;
  bottom: 20px;
  left: 20px;
  z-index: 1001;
  pointer-events: none;
}

.gift {
  font-size: 32px;
  position: absolute;
  animation: giftBounce 2s ease-in-out infinite;
}

.gift-1 {
  left: 0;
  animation-delay: 0s;
}

.gift-2 {
  left: 40px;
  animation-delay: 0.3s;
}

.gift-3 {
  left: 80px;
  animation-delay: 0.6s;
}

/* Bells */
.bells {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1001;
  pointer-events: none;
}

.bell {
  font-size: 32px;
  position: absolute;
  animation: bellSwing 2s ease-in-out infinite;
}

.bell-1 {
  right: 0;
  animation-delay: 0s;
}

.bell-2 {
  right: 40px;
  animation-delay: 0.5s;
}

/* Snow Effect Styles */
.snow-container {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  pointer-events: none;
  overflow: hidden;
}

.snow {
  position: fixed;
  width: 8px;
  height: 8px;
  background: white;
  border-radius: 50%;
  opacity: 0.8;
  animation: snowfall linear infinite;
}

@keyframes snowfall {
  0% {
    transform: translateY(-100vh) translateX(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  90% {
    opacity: 1;
  }
  100% {
    transform: translateY(100vh) translateX(100px);
    opacity: 0;
  }
}

/* Generate different positions, speeds and delays for snowflakes */
.snow:nth-child(2n) {
  width: 12px;
  height: 12px;
  animation-duration: 8s;
  animation-delay: -2s;
  left: 5%;
}

.snow:nth-child(3n) {
  width: 6px;
  height: 6px;
  animation-duration: 6s;
  animation-delay: -4s;
  left: 15%;
}

.snow:nth-child(4n) {
  width: 10px;
  height: 10px;
  animation-duration: 10s;
  animation-delay: -6s;
  left: 25%;
}

.snow:nth-child(5n) {
  width: 8px;
  height: 8px;
  animation-duration: 7s;
  animation-delay: -8s;
  left: 35%;
}

.snow:nth-child(6n) {
  width: 14px;
  height: 14px;
  animation-duration: 9s;
  animation-delay: -1s;
  left: 45%;
}

.snow:nth-child(7n) {
  width: 7px;
  height: 7px;
  animation-duration: 11s;
  animation-delay: -3s;
  left: 55%;
}

.snow:nth-child(8n) {
  width: 13px;
  height: 13px;
  animation-duration: 8s;
  animation-delay: -5s;
  left: 65%;
}

.snow:nth-child(9n) {
  width: 9px;
  height: 9px;
  animation-duration: 12s;
  animation-delay: -7s;
  left: 75%;
}

.snow:nth-child(10n) {
  width: 11px;
  height: 11px;
  animation-duration: 9s;
  animation-delay: -9s;
  left: 85%;
}

.snow:nth-child(11n) {
  width: 8px;
  height: 8px;
  animation-duration: 7.5s;
  animation-delay: -2.5s;
  left: 95%;
}

.snow:nth-child(12n) {
  width: 15px;
  height: 15px;
  animation-duration: 8.5s;
  animation-delay: -4.5s;
  left: 0%;
}

.snow:nth-child(13n) {
  width: 7px;
  height: 7px;
  animation-duration: 10.5s;
  animation-delay: -6.5s;
  left: 10%;
}

.snow:nth-child(14n) {
  width: 12px;
  height: 12px;
  animation-duration: 9.5s;
  animation-delay: -8.5s;
  left: 20%;
}

.snow:nth-child(15n) {
  width: 10px;
  height: 10px;
  animation-duration: 11.5s;
  animation-delay: -1.5s;
  left: 30%;
}

@keyframes treeFloat {
  0%, 100% {
    transform: translateY(0) rotate(0deg);
  }
  25% {
    transform: translateY(-5px) rotate(1deg);
  }
  50% {
    transform: scale(1) rotate(0deg);
  }
  75% {
    transform: translateY(-5px) rotate(-1deg);
  }
}

@keyframes treePulse {
  0%, 100% {
    filter: drop-shadow(0 0 10px rgba(0,0,0,0.3)) brightness(1);
  }
  50% {
    filter: drop-shadow(0 0 15px rgba(0,255,0,0.2)) brightness(1.1);
  }
}

@keyframes starRotate {
  0% {
    transform: translateX(-50%) rotate(0deg) scale(1);
  }
  50% {
    transform: translateX(-50%) rotate(180deg) scale(1.2);
  }
  100% {
    transform: translateX(-50%) rotate(360deg) scale(1);
  }
}

@keyframes twinkle {
  0%, 100% { 
    opacity: 1;
    text-shadow: 0 0 10px #FFD700, 0 0 20px #FFD700;
  }
  50% { 
    opacity: 0.5;
    text-shadow: 0 0 5px #FFD700;
  }
}

@keyframes lightBlink {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
}

@keyframes santaFly {
  0% {
    left: -100px;
    transform: translateY(0);
  }
  50% {
    transform: translateY(-30px);
  }
  100% {
    left: calc(100% + 100px);
    transform: translateY(0);
  }
}

@keyframes giftBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

@keyframes bellSwing {
  0%, 100% { transform: rotate(0deg); }
  25% { transform: rotate(15deg); }
  75% { transform: rotate(-15deg); }
}

/* Easter Egg Styles */
.gifts-shower {
  position: absolute;
  width: 200%;
  height: 200%;
  left: -50%;
  top: -100%;
  pointer-events: none;
}

.gift-particle {
  position: absolute;
  font-size: 24px;
  animation: giftFall 2s ease-out forwards;
}

/* Position gift particles */
.gift-particle:nth-child(1) { left: 10%; animation-delay: 0s; }
.gift-particle:nth-child(2) { left: 20%; animation-delay: 0.1s; }
.gift-particle:nth-child(3) { left: 30%; animation-delay: 0.2s; }
.gift-particle:nth-child(4) { left: 40%; animation-delay: 0.3s; }
.gift-particle:nth-child(5) { left: 50%; animation-delay: 0.4s; }
.gift-particle:nth-child(6) { left: 60%; animation-delay: 0.5s; }
.gift-particle:nth-child(7) { left: 70%; animation-delay: 0.15s; }
.gift-particle:nth-child(8) { left: 80%; animation-delay: 0.25s; }
.gift-particle:nth-child(9) { left: 90%; animation-delay: 0.35s; }
.gift-particle:nth-child(10) { left: 15%; animation-delay: 0.45s; }
.gift-particle:nth-child(11) { left: 25%; animation-delay: 0.55s; }
.gift-particle:nth-child(12) { left: 35%; animation-delay: 0.65s; }
.gift-particle:nth-child(13) { left: 45%; animation-delay: 0.75s; }
.gift-particle:nth-child(14) { left: 55%; animation-delay: 0.85s; }
.gift-particle:nth-child(15) { left: 65%; animation-delay: 0.95s; }

@keyframes treeShake {
  0%, 100% {
    transform: rotate(0deg) scale(1);
  }
  25% {
    transform: rotate(-5deg) scale(1.1);
  }
  50% {
    transform: rotate(0deg) scale(1.15);
  }
  75% {
    transform: rotate(5deg) scale(1.1);
  }
}

@keyframes giftFall {
  0% {
    transform: translateY(0) rotate(0deg) scale(0);
    opacity: 0;
  }
  10% {
    opacity: 1;
    transform: translateY(10%) rotate(45deg) scale(1);
  }
  100% {
    transform: translateY(1000%) rotate(360deg) scale(0.5);
    opacity: 0;
  }
}

/* Christmas Message Styles */
.christmas-message {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  overflow: hidden;
}

.message-content {
  text-align: center;
  transform-origin: center center;
  position: relative;
}

.message-text-container {
  position: relative;
  z-index: 2;
}

.message-text {
  font-family: 'Arial', sans-serif;
  font-weight: bold;
  line-height: 1.2;
  letter-spacing: 2px;
  position: relative;
}

.message-text-merry {
  font-size: 5rem;
  color: #ff3366;
  text-shadow: 0 0 10px #ff3366,
               0 0 20px #ff3366,
               0 0 30px #ff3366,
               0 0 40px #ff3366;
  animation: textGlow 2s infinite, textBounce 1s infinite;
}

.message-text-christmas {
  font-size: 6rem;
  color: #33ff66;
  text-shadow: 0 0 10px #33ff66,
               0 0 20px #33ff66,
               0 0 30px #33ff66,
               0 0 40px #33ff66;
  animation: textGlow 2s infinite 0.5s, textBounce 1s infinite 0.5s;
}

.message-snowflakes {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.message-snowflake {
  position: absolute;
  color: #fff;
  font-size: 1.5rem;
  animation: messageSnowfall 3s linear infinite;
  opacity: 0.8;
}

.message-stars {
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
}

.message-star {
  position: absolute;
  font-size: 1.2rem;
  animation: starTwinkle 2s ease-in-out infinite;
}

.message-decorations {
  margin-top: 30px;
  display: flex;
  justify-content: center;
  gap: 20px;
}

.message-decoration {
  font-size: 3rem;
  display: inline-block;
  animation: decorationPop 0.5s ease-out backwards;
}

.message-decoration:nth-child(1) { animation-delay: 0.2s; }
.message-decoration:nth-child(2) { animation-delay: 0.4s; }
.message-decoration:nth-child(3) { animation-delay: 0.6s; }
.message-decoration:nth-child(4) { animation-delay: 0.8s; }
.message-decoration:nth-child(5) { animation-delay: 1s; }

/* Position snowflakes */
.message-snowflake:nth-child(1) { left: 5%; animation-delay: 0.2s; }
.message-snowflake:nth-child(2) { left: 15%; animation-delay: 0.4s; }
.message-snowflake:nth-child(3) { left: 25%; animation-delay: 0.6s; }
.message-snowflake:nth-child(4) { left: 35%; animation-delay: 0.8s; }
.message-snowflake:nth-child(5) { left: 45%; animation-delay: 1.0s; }
.message-snowflake:nth-child(6) { left: 55%; animation-delay: 1.2s; }
.message-snowflake:nth-child(7) { left: 65%; animation-delay: 1.4s; }
.message-snowflake:nth-child(8) { left: 75%; animation-delay: 1.6s; }
.message-snowflake:nth-child(9) { left: 85%; animation-delay: 1.8s; }
.message-snowflake:nth-child(10) { left: 95%; animation-delay: 2.0s; }
.message-snowflake:nth-child(11) { left: 10%; animation-delay: 2.2s; }
.message-snowflake:nth-child(12) { left: 20%; animation-delay: 2.4s; }
.message-snowflake:nth-child(13) { left: 30%; animation-delay: 2.6s; }
.message-snowflake:nth-child(14) { left: 40%; animation-delay: 2.8s; }
.message-snowflake:nth-child(15) { left: 50%; animation-delay: 3.0s; }
.message-snowflake:nth-child(16) { left: 60%; animation-delay: 0.3s; }
.message-snowflake:nth-child(17) { left: 70%; animation-delay: 0.5s; }
.message-snowflake:nth-child(18) { left: 80%; animation-delay: 0.7s; }
.message-snowflake:nth-child(19) { left: 90%; animation-delay: 0.9s; }
.message-snowflake:nth-child(20) { left: 100%; animation-delay: 1.1s; }

/* Position stars */
.message-star:nth-child(1) { left: 10%; top: 10%; animation-delay: 0.2s; }
.message-star:nth-child(2) { left: 30%; top: 20%; animation-delay: 0.4s; }
.message-star:nth-child(3) { left: 50%; top: 15%; animation-delay: 0.6s; }
.message-star:nth-child(4) { left: 70%; top: 25%; animation-delay: 0.8s; }
.message-star:nth-child(5) { left: 90%; top: 30%; animation-delay: 1.0s; }
.message-star:nth-child(6) { left: 20%; top: 40%; animation-delay: 1.2s; }
.message-star:nth-child(7) { left: 40%; top: 50%; animation-delay: 1.4s; }
.message-star:nth-child(8) { left: 60%; top: 45%; animation-delay: 1.6s; }
.message-star:nth-child(9) { left: 80%; top: 35%; animation-delay: 1.8s; }
.message-star:nth-child(10) { left: 95%; top: 5%; animation-delay: 2.0s; }

/* Message Transition */
.message-enter-active {
  animation: messageIn 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.message-leave-active {
  animation: messageOut 0.6s cubic-bezier(0.6, -0.28, 0.735, 0.045);
}

@keyframes messageIn {
  0% {
    opacity: 0;
    transform: scale(0.3) rotate(-10deg);
  }
  60% {
    transform: scale(1.1) rotate(5deg);
  }
  80% {
    transform: scale(0.95) rotate(-2deg);
  }
  100% {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}

@keyframes messageOut {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  100% {
    opacity: 0;
    transform: scale(0.3) translateY(-100vh);
  }
}

@keyframes textGlow {
  0%, 100% {
    filter: brightness(1);
    transform: scale(1);
  }
  50% {
    filter: brightness(1.3);
    transform: scale(1.05);
  }
}

@keyframes textBounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

@keyframes messageSnowfall {
  0% {
    transform: translateY(-100%) rotate(0deg);
    opacity: 0;
  }
  20% {
    opacity: 0.8;
  }
  100% {
    transform: translateY(100vh) rotate(360deg);
    opacity: 0;
  }
}

@keyframes starTwinkle {
  0%, 100% {
    transform: scale(1);
    opacity: 0.5;
  }
  50% {
    transform: scale(1.5);
    opacity: 1;
  }
}

@keyframes decorationPop {
  0% {
    transform: scale(0) rotate(-180deg);
    opacity: 0;
  }
  60% {
    transform: scale(1.2) rotate(10deg);
  }
  100% {
    transform: scale(1) rotate(0);
    opacity: 1;
  }
}

.click-hint {
  position: absolute;
  top: 50%;
  left: -80px;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: hintPulse 2s ease-in-out infinite;
  pointer-events: none;
}

.click-icon {
  font-size: 24px;
  margin-bottom: 5px;
  animation: clickBounce 1s infinite;
}

.click-text {
  font-size: 14px;
  color: #fff;
  text-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
  font-weight: bold;
}

@keyframes hintPulse {
  0%, 100% {
    opacity: 0.8;
    transform: translateY(-50%) scale(1);
  }
  50% {
    opacity: 1;
    transform: translateY(-50%) scale(1.1);
  }
}

@keyframes clickBounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-5px);
  }
}

.music-control {
  position: absolute;
  top: -30px;
  right: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
  z-index: 1002;
}

.music-control:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: scale(1.1);
}

.music-icon {
  font-size: 16px;
  line-height: 1;
}
</style>
